package com.wtwd.campus.vcom.utils;

import com.wtwd.campus.service.RedisService;
import com.wtwd.campus.utils.BinaryUtil;
import com.wtwd.campus.vcom.common.Constant;

import java.util.concurrent.TimeUnit;

/**
 * @Author: ldaoliang
 * @DateTime: 2022/1/4 16:34
 * @Description: 在该类中构建MqMessage并且发送到mq并且保存到数据库中
 */
public class RequestIdUtils {

    /**
     * 生成请求Id
     * @param redisService
     * @param vcomTypeCustomerId
     * @return
     */
    public static synchronized String generateRequestId(RedisService redisService,Integer vcomTypeCustomerId){
        String currentRequestId = redisService.getRequestIdByVcomTypeCustomerId(vcomTypeCustomerId);
        String nextRequestId = "";
        if(currentRequestId.equals("FFFFFF")){
            nextRequestId = "000000";
        }else{
            int currentValue = BinaryUtil.hexString2Int(currentRequestId);
            currentValue += 1;
            nextRequestId = BinaryUtil.int2fourCharHexStr(currentValue);
        }
        redisService.setKey(Constant.REQUESTID_PREFIX + vcomTypeCustomerId,nextRequestId,0, TimeUnit.MINUTES);
        return nextRequestId;
    }

}
